package service

import (
	"log"
	"tdd/mock/db"
)

type UserService struct {
	db db.UserDBI
}

// NewUserService 实例化用户服务
func NewUserService(db db.UserDBI) *UserService {
	var userService UserService
	userService.db = db

	return &userService
}

// Login 登录
func (userService *UserService) Login(name, password string) (*db.User, error) {
	user, err := userService.db.Get(name, password)
	if err != nil {
		log.Println(err)
		return nil, err
	}

	return user, nil
}
